var express = require('express');
var router = express.Router();

const { 
  createComment,
  getComment,
  getPostComments,
  updateComment,
  likeComment,
  unlikeComment,
  deleteComment 
} = require('../controllers/comments');

/**
 * @swagger
 * tags:
 *   name: Comments
 *   description: 评论管理系统
 */

/**
 * @swagger
 * /comments:
 *   post:
 *     summary: 创建新评论
 *     tags: [Comments]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - postId
 *               - userId
 *               - content
 *             properties:
 *               postId:
 *                 type: integer
 *                 example: 123
 *               userId:
 *                 type: integer
 *                 example: 456
 *               content:
 *                 type: string
 *                 example: 这是一条精彩评论
 *     responses:
 *       201:
 *         description: 评论创建成功
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/Comment'
 *       400:
 *         description: 参数缺失或无效
 */
router.post('/', createComment);

/**
 * @swagger
 * /comments/{id}:
 *   get:
 *     summary: 获取单个评论详情
 *     tags: [Comments]
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: integer
 *         required: true
 *         description: 评论ID
 *     responses:
 *       200:
 *         description: 成功获取评论
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/Comment'
 *       404:
 *         description: 评论不存在
 */
router.get('/:id', getComment);

/**
 * @swagger
 * /comments/post/{id}:
 *   get:
 *     summary: 分页获取帖子评论
 *     tags: [Comments]
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: integer
 *         required: true
 *         description: 帖子ID
 *       - $ref: '#/components/parameters/pageParam'
 *       - $ref: '#/components/parameters/limitParam'
 *     responses:
 *       200:
 *         description: 成功获取评论列表
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 data:
 *                   type: array
 *                   items:
 *                     $ref: '#/components/schemas/Comment'
 *                 pagination:
 *                   $ref: '#/components/schemas/Pagination'
 */
router.get('/post/:id', getPostComments);

/**
 * @swagger
 * /comments/{id}:
 *   put:
 *     summary: 更新评论内容
 *     tags: [Comments]
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: integer
 *         required: true
 *         description: 评论ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - content
 *             properties:
 *               content:
 *                 type: string
 *                 example: 更新后的评论内容
 *     responses:
 *       200:
 *         description: 评论更新成功
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/Comment'
 *       404:
 *         description: 评论不存在
 */
router.put('/:id', updateComment);

/**
 * @swagger
 * /comments/like/{id}:
 *   put:
 *     summary: 点赞评论
 *     tags: [Comments]
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: integer
 *         required: true
 *         description: 评论ID
 *     responses:
 *       200:
 *         description: 点赞成功
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/Comment'
 *       404:
 *         description: 评论不存在
 */
router.put('/like/:id', likeComment);

/**
 * @swagger
 * /comments/unlike/{id}:
 *   put:
 *     summary: 取消点赞
 *     tags: [Comments]
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: integer
 *         required: true
 *         description: 评论ID
 *     responses:
 *       200:
 *         description: 取消点赞成功
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/Comment'
 *       404:
 *         description: 评论不存在
 */
router.put('/unlike/:id', unlikeComment);

/**
 * @swagger
 * /comments/{id}:
 *   delete:
 *     summary: 删除评论
 *     tags: [Comments]
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: integer
 *         required: true
 *         description: 评论ID
 *     responses:
 *       204:
 *         description: 评论删除成功
 *       404:
 *         description: 评论不存在
 */
router.delete('/:id', deleteComment);

module.exports = router;